﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebManager.Function.Portal
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LYQ.BLL.PortalList bll = new LYQ.BLL.PortalList();

                PortalFilter.DataTextField = "PortalName";
                PortalFilter.DataValueField = "PortalID";
                PortalFilter.DataSource = bll.GetModelList(" 1=1 order by PortalID asc");
                PortalFilter.DataBind();
                ListItem item = new ListItem("所有","1=1");
                PortalFilter.Items.Insert(0, item);
                BindData();
            }
        }

        private void BindData()
        {
            string where;
            if (PortalFilter.SelectedIndex == 0)
            {
                where = PortalFilter.Items[0].Value;
            }
            else
            {
                where = "PortalID=" + PortalFilter.SelectedValue;
            }

            where += " ORDER BY  PortalID ASC,CTime desc";
            LYQ.BLL.Portal bll = new LYQ.BLL.Portal();
            GridView1.DataSource = bll.GetList(where);
            GridView1.DataBind();
        }
     

        protected void Delete_Click(object sender, EventArgs e)
        {      
            Label label = Page.Master.FindControl("lblTitle") as Label;
            string msg;
           
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
               msg = "请选择要删除的文章";
               label.Text = "<b>"+msg+"</b>";
               return;
            }
            string[] sels = sel.Split(',');
            LYQ.BLL.Portal bll = new LYQ.BLL.Portal();
            foreach (string t in sels)
            {
                string [] p = t.Split(';');
                bll.Delete(Convert.ToInt32(p[0]), p[1]);
            }
            string url = URLUtility.UrlBase + "/WebManager/Function/Portal/List.aspx";
            Page.Response.Redirect(url);

        }

        protected void PortalFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.PageIndex = 0;
            BindData();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

    
    }
}
